﻿using AutoMapper;
using Decoration.Comm;
using Decoration.IService;
using Decoration.Models;
using Decoration.Models.Dto;
using Decoration.Models.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace Decoration.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UserProcedureRecordController : ControllerBase
    {
        private readonly IUserProcedureRecordService svc;
        private readonly IMapper mapper;

        public UserProcedureRecordController(IUserProcedureRecordService svc,IMapper mapper)
        {
            this.svc = svc;
            this.mapper = mapper;
        }

        [HttpGet("getAll")]
        public Result Get()
        {
            var data = svc.Query(o => true);

            return new Result() { code = 1, msg = "成功", data = data };
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public Result Add(UserProcedureRecordPostDto dto)
        {
            var data = mapper.Map<UserProcedureRecord>(dto);

            if (svc.Add(data))
                return new Result() { code = 1, msg = "成功" };
            else
                return new Result() { code = -1, msg = "失败" };
        }

        
    }
}
